package com.wanxi.version3;

//基本玩法，角色名称自己选择，玩家的血量、体能、蓝量初始均为200，NPC的初始化均为100，
// 魔法攻击一次，攻击者蓝量减少10，造成伤害20，被攻击者血量减少20；
// 物理攻击一次，攻击者体能减少10，造成伤害20，被攻击者血量减少20；
public class Gamer implements Attack {
    private String name;
    private int bloodVolume = 200;//血量
    private int physical = 200;//体能
    private int blueAmount = 200;//蓝量

    public Gamer(String name) {
        this.name = name;
    }

    public Gamer() {
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getBloodVolume() {
        return bloodVolume;
    }

    public void setBloodVolume(int bloodVolume) {
        this.bloodVolume = bloodVolume;
    }

    public int getPhysical() {
        return physical;
    }

    public void setPhysical(int physical) {
        this.physical = physical;
    }

    public int getBlueAmount() {
        return blueAmount;
    }

    public void setBlueAmount(int blueAmount) {
        this.blueAmount = blueAmount;
    }

    @Override
    public void magicAttack(Object o) {
        if (o instanceof Gamer) {
            Gamer gamer = (Gamer) o;
            if (gamer.getBloodVolume() > 0) {
                if (blueAmount >= 10) {
                    blueAmount = blueAmount - 10;
                    gamer.setBloodVolume(gamer.getBloodVolume() - 20);
                    if (gamer.getBloodVolume() <= 0) {
                        System.out.println(gamer.getName() + "死亡");
                    }
                } else {
                    System.out.println(getName()+"蓝量不足，无法施展魔法攻击");
                }
            } else {
                System.out.println(gamer.getName() + "已经死亡，无法魔法攻击");
            }
        } else if (o instanceof NPC) {
            NPC npc = (NPC) o;
            if (npc.getBloodVolume() > 0) {
                if (blueAmount >= 10) {
                    blueAmount = blueAmount - 10;
                    npc.setBloodVolume(npc.getBloodVolume() - 20);
                    if (npc.getBloodVolume() <= 0) {
                        System.out.println(npc.getName() + "死亡");
                    }
                } else {
                    System.out.println(getName()+"蓝量不足，无法施展魔法攻击");
                }
            } else {
                System.out.println(npc.getName() + "已经死亡，无法魔法攻击");
            }
        }
    }

    @Override
    public void physicalAttack(Object o) {
        if (o instanceof Gamer) {
            Gamer gamer = (Gamer) o;
            if (gamer.getBloodVolume() > 0) {
                if (physical >= 10) {
                    physical = physical - 10;
                    gamer.setBloodVolume(gamer.getBloodVolume() - 20);
                    if (gamer.getBloodVolume() <= 0) {
                        System.out.println(gamer.getName() + "死亡");
                    }
                } else {
                    System.out.println(getName()+"体能不足，无法施展物理攻击");
                }
            } else {
                System.out.println(gamer.getName() + "已经死亡，无法物理攻击");
            }
        } else if (o instanceof NPC) {
            NPC npc = (NPC) o;
            if (npc.getBloodVolume() > 0) {
                if (physical >= 10) {
                    physical = physical - 10;
                    npc.setBloodVolume(npc.getBloodVolume() - 20);
                    if (npc.getBloodVolume() <= 0) {
                        System.out.println(npc.getName() + "死亡");
                    }
                } else {
                    System.out.println(getName()+"体能不足，无法施展物理攻击");
                }
            } else {
                System.out.println(npc.getName() + "已经死亡，无法物理攻击");
            }
        }
    }


    @Override
    public String toString() {
        final StringBuffer sb = new StringBuffer("Gamer{");
        sb.append("name='").append(name).append('\'');
        sb.append(", bloodVolume=").append(bloodVolume);
        sb.append(", physical=").append(physical);
        sb.append(", blueAmount=").append(blueAmount);
        sb.append('}');
        return sb.toString();
    }
}
